package Login.servlet;

import Login.Service.BookService;
import Login.entity.Book;
import Login.util.ConnectMySql;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Connection;

@WebServlet(name = "adServlet",urlPatterns = "/add")
public class addServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        Book book = new Book();
        book.setBookId(request.getParameter("bookId"));
        book.setBookName(request.getParameter("bookName"));
        book.setBookStatus(request.getParameter("bookStatus"));
        BookService bookService = new BookService();
        if (!bookService.hasSession(request.getSession(), response)) {
            return;
        }
        int ret = bookService.addBook(book);
        if (ret > 0) {
            response.sendRedirect("list");
        }
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    }
}
